import { createContext, useContext } from 'react';

export interface contextProp {
  directory: string[];
  setDirectory: (directory: string[]) => void;

  rootFolders: string[];
  setRootFolders: (directory: string[]) => void;

  rtl: boolean;
  setRtl: (b: boolean) => void;
}

export const globalContext = createContext<contextProp | undefined>(undefined);

export const useDirectory = () => {
  const ctx = useContext(globalContext);
  if (!ctx) {
    throw new Error('useAuth必须在AuthProvider中使用');
  }
  const { directory, setDirectory } = ctx;
  return { directory, setDirectory };
};

export const useRootFolders = () => {
  const ctx = useContext(globalContext);
  if (!ctx) {
    throw new Error('useAuth必须在AuthProvider中使用');
  }
  const { rootFolders, setRootFolders } = ctx;
  return { rootFolders, setRootFolders };
};

export const useSettings = () => {
  const ctx = useContext(globalContext);
  if (!ctx) {
    throw new Error('useAuth必须在AuthProvider中使用');
  }
  const { rtl, setRtl } = ctx;
  return { rtl, setRtl };
};
